home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15211 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1004 b 

  1. Path: grimsel.zurich.ibm.com!usenet
  2. From: wgk@zurich.ibm.com (Keith Whittingham)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: another overloading question
  5. Date: 4 Apr 1996 07:14:45 GMT
  6. Organization: IBM Research, ZRH
  7. Distribution: world
  8. Message-ID: <4jvst5$snq@grimsel.zurich.ibm.com>
  9. References: <4ju98d$3al@panoramix.fi.upm.es>
  10. Reply-To: wgk@zurich.ibm.com
  11. NNTP-Posting-Host: pine.zurich.ibm.com
  12. X-Newsreader: IBM NewsReader/2 v1.00
  13.  
  14. In <4ju98d$3al@panoramix.fi.upm.es>, sacha@diafi.upm.es (Sacha) writes:
  15. >
  16. >Hi,
  17. >
  18. >Can I overload = for simple types?
  19. >
  20. >    Colour colour(0.99238, 0.172364, 0.273);
  21. >
  22. >    int intensity = colour;
  23. >
  24. >    class Colour
  25. >    {
  26. >    private:
  27. >      float r_, g_, b_;
  28. >
  29. >    public:
  30. >      Colour(float r, float g, float b) 
  31. >        {r_=r; g_=g; b_=b;}
  32. ++++      int operator=(void)
  33. ++++        { return (r_ + g_ + b_) / 3; }
  34. >    };
  35. >
  36. >is there some way I can overload = so that I can do things like:
  37. >
  38. >    Colour colour(0.99238, 0.172364, 0.273);
  39. >
  40. >    int intensity = colour;
  41. >
  42.  
  43. That should do the trick
  44.  
  45. Keith
  46.  
  47.  
  48.